package com.timebank.volunteer.factory;

import com.timebank.common.core.result.Result;
import com.timebank.volunteer.pojo.entity.VolunteerList;
import com.timebank.volunteer.pojo.vo.VolunteerAttendListVO;
import com.timebank.volunteer.service.RemoteVolunteerService;
import com.timebank.volunteer.pojo.entity.Volunteer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 志愿服务 服务降级处理
 * @author shiliuyinzhen
 */
@Component
public class RemoteVolunteerFallBackFactory implements FallbackFactory<RemoteVolunteerService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteVolunteerFallBackFactory.class);

    @Override
    public RemoteVolunteerService create(Throwable throwable) {
        log.error("志愿服务服务调用失败:{}", throwable.getMessage());
        return new RemoteVolunteerService(){
            @Override
            public Result<Volunteer> getVolunteerById(Long volunteerId, String source) {
                return  Result.fail("根据志愿服务Id查询志愿服务信息调用失败：{}" + throwable.getMessage());
            }

            @Override
            public Result<List<VolunteerList>> getVolunteerListByVolunteerId(Long volunteerId, String source) {
                return Result.fail("根据志愿服务Id查询志愿服务参与列表调用失败：{}" + throwable.getMessage());
            }

            @Override
            public Result<List<VolunteerAttendListVO>> getVolunteerAttendListByVolunteerId(Long volunteerId, String source) {
                return Result.fail("根据志愿服务Id查询志愿服务出席名单调用失败：{}" + throwable.getMessage());
            }
        };
    }

}
